<template>
  <div class="danyuan">
    <div class="myself_content" v-show="!show_top">
      <img src="../../assets/shouyeimg.png" />
      <h2>欢迎来到易分</h2>
      <img src="../../assets/anniu .png" class="Img_content" @click="to_login" />
    </div>

    <div class="myself_content_myself" v-show="show_top">
      <div class="flex_start_content">
        <div>
          <img src="../../assets/header (2).png" />
        </div>
        <div>
          <p>易分环保达人</p>
          <p>争做环保小卫士，做好易分垃圾分类</p>
        </div>
        <p class="bian_p" @click="ongogai">编辑</p>
      </div>

      <div class="bg_content_confim">
        <div @click="to_dang_qian_ji_fen">
          <span>{{currentIntegral | formatShow}}</span>
          <br />
          <span style="font-size: 13px;">当前积分<van-icon name="arrow" style="vertical-align: middle"/></span>
        </div>
        <div>
          <span>{{participantsCount }}</span>
          <br />
          <span style="font-size: 13px;">参与次数</span>
        </div>
        <div>
          <span>{{accumulateIntegral | formatShow}}</span>
          <br />
          <span style="font-size: 13px;">累计积分</span>
        </div>
        <div>
        	<span style="width: 0.5vw;height: 4vh;background: #FFFFFF;display: inline-block;"></span>
        </div>
        <div @click="to_xuan_jiao">
          <span>{{edu_intrgral}}</span>
          <br />
          <span style="font-size: 13px;">宣教积分<van-icon name="arrow" style="vertical-align: middle"/></span>
        </div>
      </div>
    </div>

    <!--<div style="margin-top: 1vh;margin-bottom: 1vh;">
			<van-cell title="回收员" icon="location-o" is-link  to="index"></van-cell>
		    <van-cell title="智能回收柜" icon="location-o" is-link />
    </div>-->

    <div>
      <!--<van-cell title="实名认证" icon="location-o" is-link /></van-cell>-->
      <van-cell title="实名认证"  is-link  @click="to_Authentication">
        <span>{{realAuthState}}</span>
      </van-cell>
      <van-cell title="帮助中心"  is-link to="myhelp" />
      <van-cell title="法律条款及隐私政策"  is-link   to="Tucao" />
      <van-cell title="意见反馈"  is-link to="opinion" />
      <van-cell title="退出登录"  @click="log_out" v-show="show_login_out"/>
    </div>



    <div>
    	 <ban-veriFy></ban-veriFy>
    </div>





  </div>
</template>
<script>
import BanVeriFy from '@/components/BanVeriFy'
import { Dialog } from 'vant';
export default {
  data() {
    return {
        show_top: false,
        user: "",
        realAuthState: "",
        currentIntegral: "",
        accumulateIntegral: "",
        participantsCount: "",
        edu_intrgral: "",
        show_login_out:false
    };
  },
  mounted: function() {
    const that = this;
    let local_user = localStorage.getItem("user");
    if (local_user != undefined && local_user != "undefined") {
        let user = JSON.parse(local_user);
        that.show_top = true;
        that.user = user;
        that.get_user_info(user.userId);
        that.get_interal();
        that.show_login_out=true;
    } else {
      that.show_top = false;
    }
  },
    filters:{

        formatShow(intgral){
            console.log(intgral);
            if(intgral>=9999999){
                return intgral.toString().substring(0,4)+"w"
            }else{
                return intgral;
            }
        }


    },
  methods: {
    to_login() {
      this.$router.push({
        path: "/"
      });
    },
    ongogai(){
      this.$router.push({
        path: "/compile"

      });
    },
      to_xuan_jiao(){
          this.$router.push({
              path: "/integral"
          });
      },
      to_dang_qian_ji_fen(){
          this.$router.push({
              path: "/withdrawals"
          });
      },
      //退出登录
    log_out(){

        Dialog.confirm({
            title: '易分',
            message: '确认要退出吗?'
        }).then(() => {
            // on confirm
            localStorage.removeItem('user');
            this.$router.push({
                path: "/banner"
            });
        }).catch(() => {
            // on cancel
        });
    },
      to_Authentication(){
          if(this.user ==''){
              Dialog.confirm({
							    title: '',
							    message: '请您先进行登录'
							}).then(() => {
							    // on confirm
							    this.$router.push({
							        path:'/'
							    })
							}).catch(() => {
							    // on cancel
							});
              return false;
          }

          if(this.user.realAuthState =='2.1'){
              //已个人认证
              this.$router.push({
                  path: "/Authenticaxue"
              });
          }else if(this.user.realAuthState =='2.2'){
              //已企业认证
              this.$router.push({
                  path: "/Authenticaqi"
              });
          }else{
              this.$router.push({
                  path: "/Authenticaperson"
              });
          }

      },
    //上一步
    goback() {
      this.$router.push({
        path: "/selectname",
        query: { cityId: this.cityId, enterpriseValue: this.enterpriseValue }
      });
    },
    get_user_info(userId) {
      const that = this;
      that.$sendRequest("/login/get_user_info", "userId=" + that.user.userId)
        .then(function(res) {
          console.log(res);
          if (res.data.code == 0) {
            localStorage.setItem("user", JSON.stringify(res.data.result.user));
            let user = JSON.parse(localStorage.getItem("user"));
            that.user = user;
            that.show_state_text();
          }
        });
    },
    //获取积分
    get_interal() {
      const that = this;
      that
        .$sendRequest("/index/get_interal", "userId=" + that.user.userId)
        .then(function(res) {
          console.log(res);
          if (res.data.code == 0) {
            that.currentIntegral = res.data.result.currentIntegral;
            that.accumulateIntegral = res.data.result.accumulateIntegral;
            that.participantsCount = res.data.result.participantsCount;
            that.edu_intrgral = res.data.result.edu_intrgral;
          }
        });
    },
    show_state_text() {
      const that = this;
      let s = that.user.realAuthState;
      if (s == "0") {
        that.realAuthState = "未认证";
      } else if (s == "1") {
        that.realAuthState = "认证中";
      } else if (s == "2.1") {
        that.realAuthState = "已认证";
      } else if (s == "2.2") {
        that.realAuthState = "已认证";
      } else if (s == "3") {
        that.realAuthState = "认证失败";
      }
     }
   },
   components: {

	  BanVeriFy

	}

};
</script>
<style scoped="scoped">
.danyuan {
  background: rgb(246, 246, 246);
  /*margin: 14px;*/
}
.danyuan >>> .van-cell__title {
  text-align: left;
}
.myself_content img {
  width: 100%;
}
.myself_content .Img_content {
  left: 10vw;
  position: absolute;
  top: 83px;
  width: 27vw;
}
.myself_content h2 {
  position: absolute;
  top: 5vh;
  color: #fff;
  font-size: 20px;
  left: 5vh;
}

.myself_content_myself {
  color: #ffffff;
  padding-top: 10vh;
  padding-left: 5vw;
  height: 29vh;
  margin-top: -3vh;
  background: url(../../assets/my.png) no-repeat center;
  background-size: cover;
}
.bg_content_confim {
  margin-right: 6vw;
  margin-top: 5vh;
}
.myself_content_myself .flex_start_content {
  display: flex;
  justify-content: flex-start;
}
.myself_content_myself .bg_content_confim {
  display: flex;
  justify-content: space-around;
}
.myself_content_myself .flex_start_content div:nth-child(2) {
  color: #ffffff;
  margin-left: 2vw;
  line-height: 4vh;
  margin-top: 2vh;
}
.myself_content_myself img {
  width: 12vh;
  height: 12vh;
}
p {
  text-align: left;
  margin: 0;
  padding: 0;
}
.myself_content_myself p:nth-child(2) {
  font-size: 13px;
}
.bian_p{
  line-height: 3.75vh;
  font-size: 0.85rem;
  border: 1px solid rgb(255, 255, 255);
  height: 3.4vh;
  width: 11vw;
  text-align: center;
  border-radius: 6px;
  position: fixed;
  right: 3vw;
}
</style>

